<template>
  <div class="app-container">
    <!-- <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px"> -->
    <!--      <el-form-item label="城市ID，可能用于关联到城市表" prop="cityId">-->
    <!--        <el-input-->
    <!--          v-model="queryParams.cityId"-->
    <!--          placeholder="请输入城市ID，可能用于关联到城市表"-->
    <!--          clearable-->
    <!--          @keyup.enter.native="handleQuery"-->
    <!--        />-->
    <!--      </el-form-item>-->
    <!--      <el-form-item label="商圈ID，可能用于关联到商圈表" prop="bizcircleId">-->
    <!--        <el-input-->
    <!--          v-model="queryParams.bizcircleId"-->
    <!--          placeholder="请输入商圈ID，可能用于关联到商圈表"-->
    <!--          clearable-->
    <!--          @keyup.enter.native="handleQuery"-->
    <!--        />-->
    <!--      </el-form-item>-->
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="商圈名称" prop="bizcircleName">
        <el-input
          v-model="queryParams.bizcircleName"
          placeholder="请输入商圈名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!--      <el-form-item label="小区的ID" prop="communityId">-->
      <!--        <el-input-->
      <!--          v-model="queryParams.communityId"-->
      <!--          placeholder="请输入小区的ID"-->
      <!--          clearable-->
      <!--          @keyup.enter.native="handleQuery"-->
      <!--        />-->
      <!--      </el-form-item>-->
      <el-form-item label="小区的名称" prop="communityName">
        <el-input
          v-model="queryParams.communityName"
          placeholder="请输入小区的名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="楼盘名称" prop="buildName">
        <el-input
          v-model="queryParams.buildName"
          placeholder="请输入楼盘名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="经纪人联系电话" prop="brokerTel">
        <el-input
          v-model="queryParams.brokerTel"
          placeholder="请输入经纪人联系电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="楼层" prop="level">
        <el-select
          v-model="queryParams.level"
          placeholder="请选择楼层"
          clearable
        >
          <el-option
            v-for="dict in dict.type.houses_level"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="区域名称" prop="districtName">
        <el-input
          v-model="queryParams.districtName"
          placeholder="请输入区域名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="销售状态" prop="saleStatus">
        <el-select
          v-model="queryParams.saleStatus"
          placeholder="请选择销售状态"
          clearable
        >
          <el-option
            v-for="dict in dict.type.house_sale_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="房屋类型" prop="houseType">
        <el-select
          v-model="queryParams.houseType"
          placeholder="请选择房屋类型"
          clearable
        >
          <el-option
            v-for="dict in dict.type.houses_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['houses:houses:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['houses:houses:edit']"
          >修改</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['houses:houses:remove']"
          >删除</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['houses:houses:export']"
          >导出</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      v-loading="loading"
      :data="housesList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="房屋id" align="center" prop="id" />
      <el-table-column label="未知字段" align="center" prop="pid" />
      <el-table-column label="城市名称" align="center" prop="cityName" />
      <el-table-column
        label="城市ID，可能用于关联到城市表"
        align="center"
        prop="cityId"
      />
      <el-table-column
        label="商圈ID，可能用于关联到商圈表"
        align="center"
        prop="bizcircleId"
      />
      <el-table-column label="商圈名称" align="center" prop="bizcircleName" />
      <el-table-column label="小区的名称" align="center" prop="communityName" />
      <el-table-column label="楼盘名称" align="center" prop="buildName" />
      <el-table-column label="经纪人联系电话" align="center" prop="brokerTel" />
      <el-table-column label="装修类型" align="center" prop="decorateType" />
      <el-table-column label="楼层" align="center" prop="level">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.houses_level"
            :value="scope.row.level"
          />
        </template>
      </el-table-column>
      <el-table-column label="户型的id" align="center" prop="specificationId" />
      <el-table-column label="朝向" align="center" prop="orientation" />
      <el-table-column label="区域名称" align="center" prop="districtName" />
      <el-table-column label="销售状态" align="center" prop="saleStatus">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.house_sale_status"
            :value="scope.row.saleStatus"
          />
        </template>
      </el-table-column>
      <el-table-column label="房屋类型" align="center" prop="houseType">
        <template slot-scope="scope">
          <dict-tag
            :options="dict.type.houses_type"
            :value="scope.row.houseType"
          />
        </template>
      </el-table-column>
      <el-table-column label="总面积" align="center" prop="totalArea" />
      <el-table-column label="详细地址" align="center" prop="addressDesc" />
      <el-table-column label="经度" align="center" prop="longitude" />
      <el-table-column label="纬度" align="center" prop="latitude" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['houses:houses:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['houses:houses:remove']"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改房屋信息列表对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="城市ID，可能用于关联到城市表" prop="cityId">
          <el-input
            v-model="form.cityId"
            placeholder="请输入城市ID，可能用于关联到城市表"
          />
        </el-form-item>
        <el-form-item label="商圈ID，可能用于关联到商圈表" prop="bizcircleId">
          <el-input
            v-model="form.bizcircleId"
            placeholder="请输入商圈ID，可能用于关联到商圈表"
          />
        </el-form-item>
        <el-form-item label="商圈名称" prop="bizcircleName">
          <el-input v-model="form.bizcircleName" placeholder="请输入商圈名称" />
        </el-form-item>
        <el-form-item label="小区的ID" prop="communityId">
          <el-input v-model="form.communityId" placeholder="请输入小区的ID" />
        </el-form-item>
        <el-form-item label="小区的名称" prop="communityName">
          <el-input
            v-model="form.communityName"
            placeholder="请输入小区的名称"
          />
        </el-form-item>
        <el-form-item label="楼盘名称" prop="buildName">
          <el-input v-model="form.buildName" placeholder="请输入楼盘名称" />
        </el-form-item>
        <el-form-item label="楼盘ID，可能作为主键或唯一标识符" prop="buildId">
          <el-input
            v-model="form.buildId"
            placeholder="请输入楼盘ID，可能作为主键或唯一标识符"
          />
        </el-form-item>
        <el-form-item label="负责经纪人id" prop="brokerId">
          <el-input v-model="form.brokerId" placeholder="请输入负责经纪人id" />
        </el-form-item>
        <el-form-item label="经纪人联系电话" prop="brokerTel">
          <el-input
            v-model="form.brokerTel"
            placeholder="请输入经纪人联系电话"
          />
        </el-form-item>
        <el-form-item label="装修类型" prop="decorateType">
          <el-input v-model="form.decorateType" placeholder="请输入装修类型" />
        </el-form-item>
        <el-form-item label="楼层" prop="level">
          <el-select v-model="form.level" placeholder="请选择楼层">
            <el-option
              v-for="dict in dict.type.houses_level"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="户型的id" prop="specificationId">
          <el-input
            v-model="form.specificationId"
            placeholder="请输入户型的id"
          />
        </el-form-item>
        <el-form-item label="朝向" prop="orientation">
          <el-input v-model="form.orientation" placeholder="请输入朝向" />
        </el-form-item>
        <el-form-item label="区域ID，可能用于关联到区域表" prop="districtId">
          <el-input
            v-model="form.districtId"
            placeholder="请输入区域ID，可能用于关联到区域表"
          />
        </el-form-item>
        <el-form-item label="区域名称" prop="districtName">
          <el-input v-model="form.districtName" placeholder="请输入区域名称" />
        </el-form-item>
        <el-form-item label="销售状态" prop="saleStatus">
          <el-select v-model="form.saleStatus" placeholder="请选择销售状态">
            <el-option
              v-for="dict in dict.type.house_sale_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="房屋类型" prop="houseType">
          <el-radio-group v-model="form.houseType">
            <el-radio
              v-for="dict in dict.type.houses_type"
              :key="dict.value"
              :label="parseInt(dict.value)"
              >{{ dict.label }}</el-radio
            >
          </el-radio-group>
        </el-form-item>
        <el-form-item label="城市名称，可能与city_id关联" prop="cityName">
          <el-input
            v-model="form.cityName"
            placeholder="请输入城市名称，可能与city_id关联"
          />
        </el-form-item>
        <el-form-item label="总面积，可能包含逗号，需要处理" prop="totalArea">
          <el-input
            v-model="form.totalArea"
            placeholder="请输入总面积，可能包含逗号，需要处理"
          />
        </el-form-item>
        <el-form-item label="详细地址" prop="addressDesc">
          <el-input
            v-model="form.addressDesc"
            type="textarea"
            placeholder="请输入内容"
          />
        </el-form-item>
        <el-form-item label="经度" prop="longitude">
          <el-input v-model="form.longitude" placeholder="请输入经度" />
        </el-form-item>
        <el-form-item label="纬度" prop="latitude">
          <el-input v-model="form.latitude" placeholder="请输入纬度" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listHouses,
  getHouses,
  delHouses,
  addHouses,
  updateHouses,
} from "@/api/houses/houses";

export default {
  name: "Houses",
  dicts: ["house_sale_status", "houses_type", "houses_level"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 房屋信息列表表格数据
      housesList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        pid: null,
        cityId: null,
        bizcircleId: null,
        bizcircleName: null,
        communityId: null,
        communityName: null,
        buildName: null,
        buildId: null,
        brokerId: null,
        brokerTel: null,
        decorateType: null,
        level: null,
        specificationId: null,
        orientation: null,
        districtId: null,
        districtName: null,
        saleStatus: null,
        houseType: null,
        cityName: null,
        totalArea: null,
        addressDesc: null,
        longitude: null,
        latitude: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询房屋信息列表列表 */
    getList() {
      this.loading = true;
      listHouses(this.queryParams).then((response) => {
        this.housesList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        pid: null,
        cityId: null,
        bizcircleId: null,
        bizcircleName: null,
        communityId: null,
        communityName: null,
        buildName: null,
        buildId: null,
        brokerId: null,
        brokerTel: null,
        decorateType: null,
        level: null,
        specificationId: null,
        orientation: null,
        districtId: null,
        districtName: null,
        saleStatus: null,
        houseType: null,
        cityName: null,
        totalArea: null,
        addressDesc: null,
        longitude: null,
        latitude: null,
        createTime: null,
        updateTime: null,
        createBy: null,
        updateBy: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加房屋信息列表";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getHouses(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改房屋信息列表";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.id != null) {
            updateHouses(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addHouses(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除房屋信息列表编号为"' + ids + '"的数据项？')
        .then(function () {
          return delHouses(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "houses/houses/export",
        {
          ...this.queryParams,
        },
        `houses_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
